

// 文件流方式读写文件

const fs = require ('fs')
const readStream=fs.
createReadStream('data/data.json',{encoding :"utf8"})   // 可读流对象
// const writeStream = fs.createWriteStream('data/data1.json',{encoding :"utf8"})  // 可写流对象 
const writeStream = fs.createWriteStream('data/data2.json.gz',{encoding :"utf8"})  // 可写流对象 

const zlib = require('zlib')

// pipe 管道输送数据 
readStream
.pipe(zlib.createGzip())  // 压缩文件 
.pipe(writeStream)
